{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "img_width=28\n",
    "img_height=28\n",
    "channels=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "batch_size=500\n",
    "num_epochs=80\n",
    "iteraions=2\n",
    "nb_augmentation=2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "fashion_classes={0:'T恤',\n",
    "                 1:'裤子',\n",
    "                 2:'套衫',\n",
    "                 3:'裙子',\n",
    "                 4:'外套',\n",
    "                 5:'凉鞋',\n",
    "                 6:'汗衫',\n",
    "                 7:'运动鞋',\n",
    "                 8:'包',\n",
    "                 9:'踝靴'}\n",
    "mnist_classes=[i for i in range(10)]\n",
    "num_classes=10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train Samples: 60000\n",
      "Test Samples: 10000\n"
     ]
    }
   ],
   "source": [
    "import tensorflow_datasets as tfds\n",
    "train_fasion_mnist=tfds.as_numpy(tfds.load(\"fashion_mnist\",split=\"train\",data_dir=\"./\",download=True,batch_size=-1))\n",
    "X_train,y_train=train_fasion_mnist[\"image\"],train_fasion_mnist[\"label\"]\n",
    "test_fasion_mnist=tfds.as_numpy(tfds.load(\"fashion_mnist\",split=\"test\",data_dir=\"./\",download=True,batch_size=-1))\n",
    "X_test,y_test=test_fasion_mnist[\"image\"],test_fasion_mnist[\"label\"]\n",
    "print(\"Train Samples:\",len(X_train))\n",
    "print(\"Test Samples:\",len(X_test))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        ...,\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]]],\n",
       "\n",
       "\n",
       "       [[[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        ...,\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]]],\n",
       "\n",
       "\n",
       "       [[[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        ...,\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]]],\n",
       "\n",
       "\n",
       "       ...,\n",
       "\n",
       "\n",
       "       [[[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        ...,\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]]],\n",
       "\n",
       "\n",
       "       [[[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [ 75],\n",
       "         [ 15]],\n",
       "\n",
       "        ...,\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [ 64],\n",
       "         [ 38],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]]],\n",
       "\n",
       "\n",
       "       [[[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        ...,\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [150],\n",
       "         [ 66],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]],\n",
       "\n",
       "        [[  0],\n",
       "         [  0],\n",
       "         [  0],\n",
       "         ...,\n",
       "         [  0],\n",
       "         [  0],\n",
       "         [  0]]]], dtype=uint8)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 1, 8, ..., 6, 9, 9], dtype=int64)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAADgdJREFUeJzt3WtM12Ufx/HrL1IgCASChWWYh6w8bTrFbJXULGdTcrlm2SZra/NBLTvIAzttHXzg5nJtWnNz1VZrHdFWDSrdNBedhpARUah5GCaIICgQKPcT7yf3dn2+9y2J3Hzfr6effeX/Rz/+Hly/67oSfX19AYA/wy71BwBwaVB+wCnKDzhF+QGnKD/gFOUHnKL8gFOUH3CK8gNODR/IH5ZIJIbk64RJSUkyX7FihcwXLlwo8/r6epnv2bMnmj311FNyNi8vT+bWG6DHjh2TeWZmZjRrb2+Xs5WVlTI/cOCAzCsqKqLZ0aNH5awlkUjI/FK+OdvX16c/3Hk8+QGnKD/gFOUHnKL8gFOUH3CK8gNOUX7AqcRArkdeynX+YcP0/3Pnzp274D/73XfflXlhYaHMa2pqZJ6eni7zzs7OaDZp0iQ5a33v5ORkmbe0tMhcvQMxfLh+zaStrU3mOTk5Ms/IyIhmDz/8sJxV7wiEYP9eenp6ZH4xsc4PQKL8gFOUH3CK8gNOUX7AKcoPOEX5AaeGzDq/tb/6sssu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BubSdOS0uTeXt7u8wrKytlnpWVJfOBwJMfcIryA05RfsApyg84RfkBpyg/4BTlB5waMuv81h7okpISmd90000yV+u+1r50a033q6++kvmWLVtk3traGs0aGxvlbGdnp8wrKipknp6eLvPVq1dHs9raWjnb0dEhc+tY8uTk5GhmvWOwd+9emVvvCahjw0MIobq6WuYDgSc/4BTlB5yi/IBTlB9wivIDTlF+wCnKDzg1ZM7tv5Sss/HV+fEh6D3vIYSQkpIi89LS0mi2ceNGOfvQQw/JvKqqSubWOQjLli2LZtYV3NadAdZ9B01NTdHM2o8/ffp0mQ9mnNsPQKL8gFOUH3CK8gNOUX7AKcoPOEX5AaeGzH5+tXc7BHvP/blz5y74Z5eVlcl8woQJMn/ggQdkbp1Pv3Pnzmj2/vvvy9nx48fLfMSIETLPz8+XuXqPpKamRs4++OCDMp87d67Mn3zyyWhmfa/+SkpKuuBZ69/qP4UnP+AU5QecovyAU5QfcIryA05RfsAptvSel0joXZDq97Ro0SI5u27dOplbx19bn623tzeaWVdwFxQUyNxaCrS23apjy63vZW353bp1q8xnzZoVzcaNGydnx44dK3OLtdR3MZfz2NILQKL8gFOUH3CK8gNOUX7AKcoPOEX5AadY5z9v2DD9/6Da8puRkSFni4qKZJ6ZmSlza9usWos/ffq0nK2rq5O5dcR1Tk6OzLOzs6OZdSS5tU3bOlZcvWNQXl4uZ+vr62U+mLHOD0Ci/IBTlB9wivIDTlF+wCnKDzhF+QGnBnSdH8DgwZMfcIryA05RfsApyg84RfkBpyg/4BTlB5yi/IBTlB9wivIDTlF+wCnKDzhF+QGnKD/gFOUHnKL8gFOUH3CK8gNOUX7AKcoPOEX5AacoP+AU5Qec+hfohawTHQZbwAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Target: 外套\n"
     ]
    }
   ],
   "source": [
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "idx = np.random.randint(len(X_train))\n",
    "plt.imshow(np.squeeze(X_train[idx]),cmap='gray')\n",
    "plt.axis('off')\n",
    "plt.show()\n",
    "print(\"Target:\",fashion_classes[y_train[idx]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2 \n",
    "import numpy as np \n",
    "import os.path \n",
    "import copy \n",
    "     \n",
    "    # 椒盐噪声 \n",
    "def SaltAndPepper(src,percetage): \n",
    "    SP_NoiseImg=src.copy() \n",
    "    SP_NoiseNum=int(percetage*src.shape[0]*src.shape[1]) \n",
    "    for i in range(SP_NoiseNum): \n",
    "        randR=np.random.randint(0,src.shape[0]-1) \n",
    "        randG=np.random.randint(0,src.shape[1]-1) \n",
    "        randB=np.random.randint(0,3) \n",
    "        if np.random.randint(0,1)==0: \n",
    "            SP_NoiseImg[randR]=0 \n",
    "        else: \n",
    "            SP_NoiseImg[randR]=255 \n",
    "    return SP_NoiseImg \n",
    "     \n",
    "    # 高斯噪声 \n",
    "def addGaussianNoise(image,percetage): \n",
    "    G_Noiseimg = image.copy() \n",
    "    w = image.shape[1] \n",
    "    h = image.shape[0] \n",
    "    G_NoiseNum=int(percetage*image.shape[0]*image.shape[1]) \n",
    "    for i in range(G_NoiseNum): \n",
    "        temp_x = np.random.randint(0,h) \n",
    "        temp_y = np.random.randint(0,w) \n",
    "        G_Noiseimg[temp_x][temp_y][np.random.randint(1)] = np.random.randn() \n",
    "    return G_Noiseimg \n",
    "     \n",
    "    # 昏暗 \n",
    "def darker(image,percetage=0.9): \n",
    "    image_copy = image.copy() \n",
    "    w = image.shape[1] \n",
    "    h = image.shape[0] \n",
    "        #get darker \n",
    "    for xi in range(0,w): \n",
    "        for xj in range(0,h): \n",
    "            image_copy[xj,xi,0] = int(image[xj,xi,0]*percetage) \n",
    "                #image_copy[xj,xi,1] = int(image[xj,xi,1]*percetage) \n",
    "                #image_copy[xj,xi,2] = int(image[xj,xi,2]*percetage) \n",
    "    return image_copy \n",
    "     \n",
    "    # 亮度 \n",
    "def brighter(image, percetage=1.5): \n",
    "    image_copy = image.copy() \n",
    "    w = image.shape[1] \n",
    "    h = image.shape[0] \n",
    "        #get brighter \n",
    "    for xi in range(0,w): \n",
    "        for xj in range(0,h): \n",
    "            image_copy[xj,xi,0] = np.clip(int(image[xj,xi,0]*percetage),a_max=255,a_min=0) \n",
    "             #  image_copy[xj,xi,1] = np.clip(int(image[xj,xi,1]*percetage),a_max=255,a_min=0) \n",
    "            #  image_copy[xj,xi,2] = np.clip(int(image[xj,xi,2]*percetage),a_max=255,a_min=0) \n",
    "    return image_copy \n",
    "     \n",
    "    # 旋转 \n",
    "def rotate(image, angle, center=None, scale=1.0): \n",
    "    (h, w) = image.shape[:2] \n",
    "        # If no rotation center is specified, the center of the image is set as the rotation center \n",
    "    if center is None: \n",
    "        center = (w / 2, h / 2) \n",
    "    m = cv2.getRotationMatrix2D(center, angle, scale) \n",
    "    rotated = cv2.warpAffine(image, m, (w, h)) \n",
    "    return rotated \n",
    "     \n",
    "    # 翻转 \n",
    "def flip(image): \n",
    "    flipped_image = np.fliplr(image) \n",
    "    return flipped_image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in X_train:\n",
    "            if np.random.randint(0,3)==1:\n",
    "                X_train[i] = flip(X_train[i])\n",
    "            else:\n",
    "                    X_train[i] = addGaussianNoise(X_train[i], 0.3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
